// run: $exec < input
#include <iostream>

int mat[11][11] = {
	{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
	{0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0},
	{0, 0, 0, 2, 3, 4, 0, 0, 0, 0, 0},
	{0, 1, 2, 0, 0, 5, 6, 0, 0, 0, 0},
	{0, 0, 3, 0, 0, 7, 0, 9, 10, 0, 0},
	{0, 0, 4, 5, 7, 0, 8, 0, 11, 12, 0},
	{0, 0, 0, 6, 0, 8, 0, 0, 0, 13, 14},
	{0, 0, 0, 0, 9, 0, 0, 0, 15, 0, 0},
	{0, 0, 0, 0, 10, 11, 0, 15, 0, 16, 0},
	{0, 0, 0, 0, 0, 12, 13, 0, 16, 0, 17},
	{0, 0, 0, 0, 0, 0, 14, 0, 0, 17, 0}
};

int mask[9] = {7, 152, 52, 352, 34304, 3200, 71680, 12544, 155648};
int const all_state = (1 << 18) - 1;

int get_state(int old, int line, int & cnt)
{
	int now = old | line;
	for (int i = 0; i < 9; i++)
		if ((old & mask[i]) != mask[i] && (now & mask[i]) == mask[i])
			cnt++;
	return now;
}

int max_state(int state, int alpha, int c1, int c2);

int min_state(int state, int beta, int c1, int c2)
{
	if (c1 >= 5) return 1;
	if (c2 >= 5) return -1;
	if (state == all_state) return c1 > c2 ? 1 : -1;
	int ans = 1;
	int remain = (~state) & all_state;
	while (remain) {
		int line = remain & (-remain);
		int t2 = c2;
		int now = get_state(state, line, t2);
		int tmp;
		if (t2 > c2) tmp = min_state(now, beta, c1, t2);
		else tmp = max_state(now, ans, c1, t2);

		if (tmp < ans) ans = tmp;
		if (tmp <= beta) return ans;
		remain -= line;
	}
	return ans;
}

int max_state(int state, int alpha, int c1, int c2)
{
	if (c1 >= 5) return 1;
	if (c2 >= 5) return -1;
	if (state == all_state) return c1 > c2 ? 1 : -1;
	int ans = -1;
	int remain = (~state) & all_state;
	while (remain) {
		int line = remain & (-remain);
		int t1 = c1;
		int now = get_state(state, line, t1);
		int tmp;
		if (t1 > c1) tmp = max_state(now, alpha, t1, c2);
		else tmp = min_state(now, ans, t1, c2);
		if (tmp > ans) ans = tmp;
		if (tmp >= alpha) return ans;
		remain -= line;
	}
	return ans;
}

int main()
{
	std::ios::sync_with_stdio(false);
	int AT; std::cin >> AT;
	for (int tti = 1; tti <= AT; tti++) {
		if (tti > 1) std::cout << '\n';
		int T; std::cin >> T;
		for (int ti = 1; ti <= T; ti++) {
			int n;
			std::cin >> n;
			int cnt = 0, state = 0;
			int c1 = 0, c2 = 0;
			for (int i = 0, x, y; i < n; i++) {
				std::cin >> x >> y;
				int t1 = c1, t2 = c2;
				state = get_state(state, 1 << mat[x][y], (cnt & 1) ? c2 : c1);
				if (t1 == c1 && t2 == c2) cnt++;
			}
			int ans;
			if (cnt & 1) ans = min_state(state, -1, c1, c2);
			else ans = max_state(state, 1, c1, c2);
			std::cout << "Game " << ti << ": " << (ans == 1 ? 'A' : 'B') << " wins.\n";
		}
	}
}

